package com.webex.ta.hydra.gui.macro;

import com.webex.ta.hydra.gui.MenuFactory;
import com.webex.ta.hydra.gui.action.ActionNames;
import com.webex.ta.hydra.gui.action.KeyStrokes;
import com.webex.ta.hydra.gui.macro.action.MacroOpenRecentAction;
import com.webex.ta.hydra.util.HydraUtils;

import javax.swing.*;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-14
 * Time: 10:48:13
 */
public class MacroEditorMenuBar extends JMenuBar {
    private JMenu fileMenu;

    private JMenuItem file_open, file_close, file_save;

    private List file_mru_files = new LinkedList();

    public MacroEditorMenuBar() {
        super();
        populateMenus();
    }

    private void populateMenus() {
        makeFileMenu();
        add(fileMenu);
    }

    private void makeFileMenu() {
        fileMenu = new JMenu("File");
		fileMenu.setMnemonic('F');

        file_open = MenuFactory.makeMenuItem("Open", 'O', "Open", ActionNames.MACR0_OPEN, KeyStrokes.OPEN);
        file_open.setIcon(HydraUtils.getImage("prj_obj.gif"));
        file_save = MenuFactory.makeMenuItem("Save", 'S', "Save", ActionNames.MACR0_SAVE, KeyStrokes.SAVE);
        file_save.setIcon(HydraUtils.getImage("save.gif"));
        file_close = MenuFactory.makeMenuItem("Close", 'C', "Close", ActionNames.MACR0_CLOSE, KeyStrokes.CLOSE);
        file_close.setIcon(HydraUtils.getImage("close.png"));

        fileMenu.add(file_open);
        fileMenu.add(file_save);
        fileMenu.add(file_close);
        fileMenu.addSeparator();
        file_mru_files = MacroOpenRecentAction.getRecentFileMenuItems();
        for (Object file_mru_file : file_mru_files) {
            fileMenu.add((JComponent) file_mru_file);
        }
    }

    public void macroFileLoaded(String file) {
        if(file_mru_files != null && file != null) {
            MacroOpenRecentAction.updateRecentFileMenuItems(file_mru_files, file);
        }
    }
}
